﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using LGSVR.Common;

namespace LGSVR_WEB.sys
{
    public partial class UserCardGroupLeft : LGSVR.Common.DataBasePage
    {
        DataTable dt = null;
        DataSet ds = new DataSet();
        DataView dv = new DataView();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (!IsPostBack)
            BindTree();
        }
        #region 主从表绑定
        private void BindTree()
        {
            int totalRS;
            bool isSupperAdmin = Session["ActName"].ToString() == "超级管理员";
            string strWhere = " AND isnull(state,1) <>0 ";
            if (!isSupperAdmin)
            {
                strWhere += " AND companyid='" + Session["CompanyID"] + "'";
            }
            DataTable dt = GetList("company", " companyID Asc ", strWhere, 1, int.MaxValue, out totalRS);
            //tvUserCardGroup.ShowCheckBoxes = TreeNodeTypes.All;
            foreach (DataRow masterRow in dt.Rows)
            {
                TreeNode masterNode = new TreeNode(masterRow["companyName"].ToString());
                masterNode.SelectAction = TreeNodeSelectAction.Expand;
                //tvUserCardGroup.SelectedNode.Expanded = true;
                tvUserCardGroup.Nodes.Add(masterNode);

                BindLeavesTree(masterRow["companyID"].ToString(), masterNode);

            }
        }
       
  
        private void BindLeavesTree(string strID, TreeNode TN)
        {
            
            int totalRS;
            DataTable dst = GetList("userInfo", " userID Asc ", " AND companyID = '" + strID + "'", 1, int.MaxValue, out totalRS);
            foreach (DataRow childRow in dst.Rows)
            {
                //TreeNode childNode = new TreeNode(childRow["cardID"].ToString(),childRow["cardDesc"].ToString(),"messageInfoList.aspx?cardID=" + childRow["cardID"].ToString(),childRow["cardDesc"].ToString());
                TreeNode childNode = new TreeNode();
                childNode.Value = childRow["userID"].ToString();              
                childNode.Text = "<span onclick=\"javascript:return refreshpnt('" + childRow["userID"].ToString() + "','" + childRow["userName"].ToString() + "');\">" + childRow["userName"].ToString() + "</span>";
                childNode.NavigateUrl = "#";
                //childNode.NavigateUrl = "messageInfoList.aspx?cardID=" + childRow["cardID"].ToString();
                TN.Expanded = false;
                TN.ChildNodes.Add(childNode);
            }
        }
        #endregion

     

        protected void tvUserCardGroup_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            TreeNodeCollection ts = null;
            if (e.Node.Parent == null)
            {
                ts = ((TreeView)sender).Nodes;
            }
            else
                ts = e.Node.Parent.ChildNodes;
            foreach (TreeNode node in ts)
            {
                if (node != e.Node)
                {
                    node.Collapse();
                }
            }
        }

   
  

    }
}

